<?php

	require_once("adodb/adodb.inc.php");

	function dbconn($db_host, $db_username, $db_password, $db_database, $db_type){
		global $config;
	
		$db = NewADOConnection($db_type);
		$db->Connect($db_host, $db_username, $db_password, $db_database);
		$db->SetFetchMode(ADODB_FETCH_ASSOC);
		$db->Execute("set names {$config->site_charset}");
		
		return $db;
	}	

	class pager {

		var $rows = 0;
		var $pages = 0;
		var $pagecurrent = 0;
		var $limit;
		var $result;

		function pager($limit=999999, $pagecurrent=1){
			$this->limit = $limit;
			$this->pagecurrent = is_numeric($pagecurrent)?$pagecurrent:1;
		}

		function execute($adodb, $sql){
			$recordSet = $adodb->PageExecute($sql, $this->limit, $this->pagecurrent);
			$rs = array ();
			if (isset ($recordSet->fields)){
				while (!$recordSet->EOF){
					$rs[] = $recordSet->fields;
					$recordSet->MoveNext();
				}
				$this->rows = $recordSet->MaxRecordCount();
				$this->pages = $recordSet->LastPageNo() < 0 ? 0 : $recordSet->LastPageNo();
				$this->current = $recordSet->AbsolutePage() < 1 ? 1 : $recordSet->AbsolutePage();
			}
			return $this->result = $rs;
		}
	}
	
?>